package multithread.framework.threadmethod;

import java.lang.reflect.Method;

public final class ParserFactory {

	private ParserFactory(){}
	
	private static IParseFilter<?> parseFilter;

	public static void setParseFilter(IParseFilter<?> parseFilter) {
		ParserFactory.parseFilter = parseFilter;
	}

	@SuppressWarnings("unchecked")
	public static IParser<? extends IContainer> createThreadMethodParser() {
		return new ThreadMethodParser((IParseFilter<Method>) parseFilter);
	}

	@SuppressWarnings("unchecked")
	public static IParser<? extends IContainer> createXMLThreadMethodParser() {
		return new XMLThreadMethodParser((IParseFilter<Method>) parseFilter);
	}

	public static IParser<? extends IContainer> createThreadMethodParserByInstance(Object testcase) {
		if (testcase instanceof String) {// run from XML configuration file
			return ParserFactory.createXMLThreadMethodParser();
		} else {
			return ParserFactory.createThreadMethodParser();
		}
	}

}
